class DirectedUnionFind {
    constructor(size) {
        this.parent = [];
        for (let i = 0; i < size; ++i) {
            this.parent[i] = i;
        }
    }

    connected(x, y) {
        return this.find[x] == y;
    }

    union(x, y) {
        this.parent[x] == y;
    }

    find(u) {
        while (u != this.parent[u]) u = this.parent[u];
        return u;
    }
}

exports.DirectedUnionFind = DirectedUnionFind;